package test;

public class GMain2 {
	public static void main(String[] args) {
		GMain2 app = new GMain2();
		int[] vals = new int[] {6,10,2,9,1,3,6,3,7,5,3,2,7,7,4};
		for(int i = 0; i < vals.length; i++) {
			app.receiveNextElem(vals[i], i);
		}
		System.out.println(app.bestRes + " - " + app.lowIndex + " - " + app.highIndex);
	}
	
	int lowIndex = 0, lowIndexTillNow = 0, highIndex = 0;
	int low = Integer.MAX_VALUE;
	int bestRes = 0;
	void receiveNextElem(int stock, int i) {
	  int newResult = stock - low;
	  if(newResult > bestRes) {
	      bestRes = newResult;
	      highIndex = i;
	      lowIndex = lowIndexTillNow;
	  }
	  if(stock < low) {
	    lowIndexTillNow = i;
	    low = stock;
	  }
	}
}
